package com.zl.learning.thread;

public class BadLockOnInteger implements Runnable {
    public static Integer i = 0;
    private static final BadLockOnInteger instance = new BadLockOnInteger();

    @Override
    public void run() {
        for (int j = 0; j < 10000; j++) {
//            synchronized (i) {
            synchronized (instance) {
                i++;
            }
        }
    }

    static class Test1 {
        public static void main(String[] args) throws InterruptedException {
            Thread t1 = new Thread(instance);
            Thread t2 = new Thread(instance);
            t1.start();
            t2.start();
            t1.join();
            t2.join();
            System.out.println(i);
        }
    }

}
